Ext.define('AM.controller.bazadedate.PanouBazaDeDate', {

	extend : 'Ext.app.Controller',
	stores : [ 'bazadedate.Articole', 'bazadedate.Manopere',
			'bazadedate.Materiale', 'bazadedate.Transporturi',
			'bazadedate.Utilaje' ],
	views : [ 'grids.bazadedate.Articole', 'grids.bazadedate.CreazaArticol',
			'grids.bazadedate.Manopere', 'grids.bazadedate.Materiale',
			'grids.bazadedate.Transporturi', 'grids.bazadedate.Utilaje' ],

	init : function() {
		console.log('Initializare controller panou baza de date');

		this.control({
			'viewport > panel' : {
				render : this.onPanelRendered
			},
			'bazadedatearticole' : {
			// itemdblclick : this.editUser,
			// selectionchange : this.selectUser
			},

			'bazadedatearticole button[action=adaugaArticolBazaDeDate]' : {
				click : this.articolNou
			},
			'creazaArticol button[action=salveazaArticolBazaDeDate]' : {
				click : this.creazaArticol
			},
			'bazadedatearticole button[action=stergeArticolBazaDeDate]' : {
				click : this.stergeArticol
			}

		});
	},

	onPanelRendered : function() {
		// console.log('The database panel panel was rendered');

	},

	articolNou : function(button) {
		console.log('Articol nou');
		var view = Ext.widget('creazaArticol');
		view.down('form');
	},
	creazaArticol : function(button) {
		console.log('Click pe salveaza articol');
		var win = button.up('window'), form = win.down('form'), record = form
				.getRecord(), values = form.getValues();

		// record.set(values);
		console.log(values);
		var store = this.getStore('bazadedate.Articole');

		store.add(values);
		win.close();
		store.sync();
	},
	deleteUserClick : function(selModel, selections) {
		// console.log('clicked Delete');
		var viewList = Ext.ComponentQuery.query('#userID')[0];
		// console.log(viewList.getSelectionModel().getSelection()[0]);
		var selection = viewList.getSelectionModel().getSelection()[0];

		if (selection) {
			this.getUserStore().remove(selection);
			this.getUserStore().sync();
		}

	}
});
